import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '@/views/index.vue'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css' // 导入样式

// 配置 NProgress
NProgress.configure({
  showSpinner: false, // 可选：禁用加载微调器
})

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'index',
      redirect: '/home',
      component: HomeView,
      children: [
        {
          path: '/home',
          name: 'home',
          component: () => import('@/views/Home/index.vue'),
        },
      ],
    },

    {
      path: '/login',
      name: 'login',
      component: () => import('../views/Login/index.vue'),
    },
  ],
})

// 路由守卫中添加进度条
router.beforeEach((to, from, next) => {
  NProgress.start() // 开始进度条
  next()
})

router.afterEach(() => {
  NProgress.done() // 结束进度条
})

export default router
